package com.xoa.controller.attend;

import com.xoa.model.attend.Attend;
import com.xoa.model.attend.AttendFlowRunPrcs;
import com.xoa.model.attend.AttendLeave;
import com.xoa.service.attend.AttendLeaveService;
import com.xoa.util.ToJson;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.common.wrapper.BaseWrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by gsb on 2017/7/17.
 */
@RestController
@RequestMapping("/attendLeave")
public class AttendLeaveController {
@Autowired
 private AttendLeaveService attendLeaveService;

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017-7-14 下午14:45:00
     * 方法介绍:   查询请假登记
     */
    @RequestMapping(value = "/queryAllAttendLeave", produces = { "application/json;charset=UTF-8" })
    ToJson<AttendFlowRunPrcs> queryAllAttendLeave(@RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
                                                  @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                  @RequestParam(name = "useFlag", required = false, defaultValue = "true")  Boolean useFlag,
                                                  String allow, HttpServletRequest request){
        return attendLeaveService.queryAllAttendLeave(page,pageSize,useFlag,request,allow);
    }

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017-7-14 下午14:45:00
     * 方法介绍:   查询请假登记
     */
    @RequestMapping(value = "/queryAllAttendLeaveFields", produces = { "application/json;charset=UTF-8" })
    ToJson<AttendLeave> queryAllAttendLeaveFields(String tableName, HttpServletRequest request){
        return attendLeaveService.queryAllAttendLeaveFields(tableName,request);
    }

    @RequestMapping( value="/addAttendLeave")
    BaseWrapper addAttendLeave(String userId,String recordTime,HttpServletRequest request){
        return attendLeaveService.addAttendLeave(userId,recordTime,request);
    }

    @RequestMapping(value = "/backlogAttendList", produces = { "application/json;charset=UTF-8" })
    public BaseWrappers backlogAttendList(HttpServletRequest request, String num,
                                          @RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
                                          @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                          @RequestParam(name = "useFlag", required = false, defaultValue = "true")  Boolean useFlag){
        return attendLeaveService.backlogAttendList(request,num,page,pageSize,useFlag);
    }

    @RequestMapping(value="/getAllBydate", produces = { "application/json;charset=UTF-8" })
    public BaseWrapper getAllByDate(HttpServletRequest request,
                                    String startDate,
                                    String endDate,
                                    Integer length,
                                    String userId){
        return attendLeaveService.getAllByDate(startDate, endDate, length,userId);
    }
    /**
     * 左春晖
     * 请假导出
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "queryExportAttends", produces = {"application/json;charset=UTF-8"})// /attendLeave/queryExportAttends
    public ToJson<AttendLeave> queryExportAttends(HttpServletRequest request, HttpServletResponse response,
                                                  AttendLeave attendLeave,String beginDate, String isExport,
                                                  Integer page, Integer pageSize, Boolean useFlag) {
        return attendLeaveService.queryExportAttend(request,response,attendLeave,beginDate,isExport,page,pageSize,useFlag);
    }

    /**
     * 创建人：季佳伟
     * 创建时间：2017-11-21  下午5:40:17
     * 方法介绍：查询登录人一段时间内的请假状况
     * 参数说明：
     */
    @RequestMapping(value="/selectAttendLeaveByUserId", produces = { "application/json;charset=UTF-8" })
    public ToJson<AttendLeave> selectAttendLeaveByUserId(String beginDate, String endDate,HttpServletRequest req){
        return attendLeaveService.selectAttendLeaveByUserId(beginDate, endDate, req);
    }

    @RequestMapping(value="/getAttendLeaveCount", produces = { "application/json;charset=UTF-8" })
    public BaseWrapper getAttendLeaveCount(){
        return attendLeaveService.getAttendLeaveCount();
    }



    /**
     * 判断是否可以调休
     * @param userId
     * @return
     */
    @RequestMapping("/queryPaidLeave")
    @ResponseBody
    public ToJson queryPaidLeave(String userId){
        return attendLeaveService.queryPaidLeave(userId);
    }

    /**
     * 最近3个月调休总天数
     * @param userId
     * @return           ok
     */
    @RequestMapping("/allPaidLeave")
    @ResponseBody
    public ToJson allPaidLeave(String userId){
        return attendLeaveService.allPaidLeave(userId);
    }


    }
